package com.demo.lazy;

import java.util.concurrent.ThreadLocalRandom;

public class Test {

	public static void main(String[] args) {
		//Lazy.of(() -> compute(42)).get();
		System.out.println("-------------");
		//Lazy.of(() -> compute(42)).map(s -> compute(13)).get();
		System.out.println("---------------");
		//Lazy.of(() -> compute(42)).map(s -> compute(13)).filter(v -> v > 0).get();
		System.out.println("---------------");
        Lazy.of(() -> compute(42)).map(s -> compute(13)).flatMap(s -> lazyCompute(15)).filter(v -> v > 0).get();
    }

    private static int compute(int val) {
        int result = 100 / val;
        System.out.println(val + " Computed: " + result);
        return result;
    }

    private static Lazy<Integer> lazyCompute(int val) {
        return Lazy.of(() -> {
            int result = ThreadLocalRandom.current().nextInt() % val;
            System.out.println(val + " Computed: " + result);
            return result;
        });
    }

}
